package eu.jba.denshijisho;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import eu.jba.denshijisho.entity.Card;
import eu.jba.denshijisho.exceptionhandler.ExceptionHandler;
import eu.jba.denshijisho.util.Constants;

public class QuestionDisplayerActivity extends AbstractDenshiActivity {

	private Boolean doubleBackToExitPressdOnce = false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Thread.setDefaultUncaughtExceptionHandler( new ExceptionHandler( this ));
		setFinishOnTouchOutside(false);
		setContentView(R.layout.activity_question_displayer);
		final Bundle bundle = getIntent().getExtras();
		final Card card = (Card)bundle.getSerializable(Constants.CARD);
		final String step = bundle.getString(Constants.STEP);
		((TextView)findViewById(R.id.quzi_svk_Word)).setText( card.getSvkWord() );
		((TextView)findViewById(R.id.steper)).setText( step );
		((TextView)findViewById(R.id.quiz_kana_word)).setText( "..." );
		((TextView)findViewById(R.id.quiz_kanji)).setText( "..." );
	}
	
	public void wrongAnswer(View view){
		setResult(Constants.RESULT_DONT_KNOW);
		finish();
		
	}
	
	public void showAnswer(View view){
		final Bundle bundle = getIntent().getExtras();
		final Card card = (Card)bundle.getSerializable(Constants.CARD);
		((TextView)findViewById(R.id.quiz_kana_word)).setText( card.getKanaWord() );
		((TextView)findViewById(R.id.quiz_kanji)).setText( card.getKanji() );
	}
	
	public void rightAnswer(View view){
		setResult(Constants.RESULT_KNOW);
		finish();
	}

	@Override
	public void onBackPressed() {
		if( doubleBackToExitPressdOnce ){
			super.onBackPressed();
			return;
		}
		this.doubleBackToExitPressdOnce = true;
		Toast.makeText(this, "To exit quiz click Back again", Toast.LENGTH_SHORT).show();
		
		new Handler().postDelayed(
			new Runnable() {
				
				@Override
				public void run() {
					doubleBackToExitPressdOnce = false;
				}
			}, 
			2000
		);
	}
}
